#include "widget.h"
#include "ui_widget.h"
#include <QTimer>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    timer = new QTimer(this);
    connect(timer, &QTimer::timeout, this, &Widget::handle);
    // 启动定时器，启动操作需要在 connect 之后
    timer->start(100);
}

void Widget::handle()
{
    // 获取到进度条的当前数值
    int value = ui->progressBar->value();
    if(value >= 100)
    {
        timer->stop(); // 进度条满了就停止定时器
        return ;
    }
    ui->progressBar->setValue(value + 1);
}

Widget::~Widget()
{
    delete ui;
}

